package com.waters321.oneone.common.exception;

import java.text.MessageFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class GeneralException extends RuntimeException {

  private static final long serialVersionUID = 1984156164548817787L;

  /** 错误码 */
  private int code;

  /** 错误提示 */
  private String message;

  /**
   * @param code 错误码
   * @param message 错误提示信息
   * @param arguments codeMessage对象中的message字符格式化参数，
   */
  public GeneralException(int code, String message, Object... arguments) {
    this.code = code;
    initMessage(message, arguments);
  }

  private void initMessage(String message, Object[] arguments) {
    if (arguments != null && arguments.length > 0) {
      this.message = MessageFormat.format(message, arguments);
    } else {
      this.message = message;
    }
  }
}
